// pages/dingdan/dingdan.js
const $ = require("../../utils/util")
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
		typeId:0,page:1,list:[],pageMax:0,
		headerlist:[
			{
				title:"全部",
				type: 0,
			
			},
			{
				title:"待付款",
				type: 1
			},
			{
				title:"带发货",
				type: 2
			},
			{
				title:"待收货",
				type: 3
			},
			{
				title:"待评价",
				type: 4
			},
		]
  },
	getlist(){
		$.axios({
			url:"order/list",
			method:"GET",
			data:{
				showType:this.data.typeId,
				page:this.data.page,
				limit:8
			},
			header:{
				"X-Byesame-Token":wx.getStorageSync('token')
			}
		}).then(res=>{
			console.log(res);
			this.setData({
				list:this.data.list.concat(res.data.data.list),
				pageMax:res.data.data.pages
			})
		})

	},
	cdtype(e){
		this.setData({
			typeId:e.currentTarget.dataset.typeid,
			page:1,
			pageMax:0,
			list:[]
		})
		this.getlist()
	},
	goback(){
		wx.navigateBack()
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
		this.setData({
			typeId:options.typeId
		})
	
		// console.log(options,"传过来了吗111");
		// console.log(this.data.typeId,"传过来了吗");
  },
goMore(e){
	let id = e.currentTarget.dataset.id
	wx.navigateTo({
		url: '/pages/fukuanMore/fukuanMore?id='+id,
	})
},
getdel(e){
	let id = e.currentTarget.dataset.id
	Dialog.confirm({
		title: '',
		message: '确定要删除该订单吗？',
	})
		.then(() => {
			// on confirm
			$.axios({
				url:"order/delete",
				method:"POST",
				header:{
					"X-Byesame-Token":wx.getStorageSync('token')
				},
				data:{
					orderId:id
				}
			}).then(()=>{
				wx.showToast({
					title: '删除成功',
				})
				this.onPullDownRefresh()
			})
		})
		.catch(() => {
			// on cancel
			wx.showToast({
				title: '已取消操作',
			})
		
		});
},
getcancel(e){
	let id = e.currentTarget.dataset.id
	// console.log(id);
	Dialog.confirm({
	message: '确定要取消该订单吗?'
})
	.then(() => {
		// on confirm
		$.axios({
			url:"order/cancel",
			method:"POST",
			header:{
				"X-Byesame-Token":wx.getStorageSync('token')
			},
			data:{
				orderId:id
			}
		}).then(()=>{
			wx.showToast({
				title: '已取消订单',
			})
			this.onPullDownRefresh()
		})
		
	})
	.catch(() => {
		// on cancel
		wx.showToast({
			title: '已取消操作',
		})
	});
},
getpay(e){
	let id = e.currentTarget.dataset.id
	wx.navigateTo({
		url: '/pages/pay/pay?id='+id,
	})
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
	
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
		wx.hideHomeButton();
		this.onPullDownRefresh()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
		this.setData({
			page:1,
			pageMax:0,
			list:[]
		})
		this.getlist()

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
		if(this.data.page < this.data.pageMax){
			console.log(123);
			this.setData({
				page:this.data.page+1,
			})
			console.log(this.data.page);
			this.getlist()
		}
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})